package cjlu.ea.h.service.impl;

import cjlu.ea.h.entity.Bjxx;
import cjlu.ea.h.entity.ByszgshbLsb;
import cjlu.ea.h.entity.vo.statistics.F1011Vo;
import cjlu.ea.h.entity.vo.statistics.F1012Vo;
import cjlu.ea.h.entity.vo.statistics.F1013Vo;
import cjlu.ea.h.entity.vo.statistics.F1014Vo;
import cjlu.ea.h.mapper.F101ByszgshbLsbMapper;
import cjlu.ea.h.service.F101ByszgshbLsbService;
import cjlu.ea.h.service.StatisticsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import java.util.LinkedList;
import java.util.List;

@Service
@Slf4j
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    F101ByszgshbLsbMapper f101ByszgshbLsbMapper;



    @Override
    public List<F1011Vo> F1011Statistics(Bjxx bjxx) {
        List<F1011Vo> list = new LinkedList<>();
        F1011Vo f1011Vo = new F1011Vo();
        List<F1011Vo> bysList;
        if (bjxx==null){
            bysList = f101ByszgshbLsbMapper.F1011Statistics(null,null);
        }else{
             bysList = f101ByszgshbLsbMapper.F1011Statistics(bjxx.getXymc(),bjxx.getBjmc());
        }
        for (F1011Vo o: bysList) {
            float row_byl = (float)o.getBys()/(float)o.getZrs();
            String byl = String.format("%.2f",row_byl*100)+"%";
            o.setByl(byl);
            float row_xwl = (float)o.getXwrs()/(float)o.getZrs();
            String xwl = String.format("%.2f",row_xwl*100)+"%";
            o.setXwl(xwl);
        }
        return bysList;
    }

    @Override
    public List<F1012Vo> F1012Statistics(Bjxx bjxx) {
        List<F1012Vo> list;
        if (bjxx==null){
            list = f101ByszgshbLsbMapper.F1012Statistics(null,null);
        }else{
            list = f101ByszgshbLsbMapper.F1012Statistics(bjxx.getXymc(),bjxx.getBjmc());
        }

        return list;
    }

    @Override
    public List<ByszgshbLsb> F1013List(Bjxx bjxx) {
        List<ByszgshbLsb> list;
        if (bjxx==null){
            list = f101ByszgshbLsbMapper.F1013List(null,null);
        }else{
            list = f101ByszgshbLsbMapper.F1013List(bjxx.getXymc(),bjxx.getBjmc());
        }

        return list;

    }

    @Override
    public List<F1013Vo> F1013Statistics(Bjxx bjxx) {
        List<F1013Vo> list;
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("bz","结业");
        if (bjxx==null){
            list = f101ByszgshbLsbMapper.F1013Statistics(null,null);
        }else{
            list = f101ByszgshbLsbMapper.F1013Statistics(bjxx.getXymc(),bjxx.getBjmc());
        }

        int count = f101ByszgshbLsbMapper.selectCount(queryWrapper);
        for (F1013Vo o: list) {
            float row_byl = (float)o.getRs()/(float)count;
            String bl = String.format("%.2f",row_byl*100)+"%";
            o.setBl(bl);
            o.setZrs(count);
        }

        return list;
    }

    @Override
    public List<ByszgshbLsb> F1014List(Bjxx bjxx) {
        List<ByszgshbLsb> list;
        if (bjxx==null){
            list = f101ByszgshbLsbMapper.F1014List(null,null);
        }else{
            list = f101ByszgshbLsbMapper.F1014List(bjxx.getXymc(),bjxx.getBjmc());
        }

        return list;
    }

    @Override
    public List<F1014Vo> F1014Statistics(Bjxx bjxx) {
        List<F1014Vo> list;
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("bz","结业");
        if (bjxx==null){
            list = f101ByszgshbLsbMapper.F1014Statistics(null,null);
        }else{
            list = f101ByszgshbLsbMapper.F1014Statistics(bjxx.getXymc(),bjxx.getBjmc());
        }

        int count = f101ByszgshbLsbMapper.selectCount(queryWrapper);
        for (F1014Vo o: list) {
            float row_byl = (float)o.getRs()/(float)count;
            String bl = String.format("%.2f",row_byl*100)+"%";
            o.setBl(bl);
            o.setZrs(count);
        }

        return list;
    }

    @Override
    public List<ByszgshbLsb> F1015List(Bjxx bjxx) {
        List<ByszgshbLsb> list;
        if (bjxx==null){
            list = f101ByszgshbLsbMapper.F1015List(null,null);
        }else{
            list = f101ByszgshbLsbMapper.F1015List(bjxx.getXymc(),bjxx.getBjmc());
        }

        return list;
    }
}
